import React, { useState, useEffect } from 'react'
import { Popconfirm, Modal, Input, Table, Button } from 'antd'
import { useHistory, Switch } from 'react-router-dom';


import List from './List';
import LoopMsgAPi from '../../../../../../../utils/apis/LoopMsgAPi';

export default function ApprovalInformationList(props) {
  const { data, item } = props;
  const [switchState, setSwitchState] = useState(false);
  const [title, setTitle] = useState(false);
  const [dataList, setDataList] = useState();
  const [tqDataList, setTqDataList] = useState();
  const [ygd, setYhd] = useState();
  const history = useHistory();


  const onOk = () => {
    setSwitchState(false)
  }

  useEffect(() => {
    //console.log("@123-->",item)
    /* 
    {
          label: '调查管理',
          key: '1',
          //icon: <MailOutlined />,
        },
        {
          label: '排查治理',
          key: '2',
         // icon: <AppstoreOutlined />,
          //disabled: true,
        },
        {
            label: '辅助信息',
            key: '3',
           // icon: <AppstoreOutlined />,
            //disabled: true,
        },
        {
            label: '隐患点管理',
            key: '4',
           // icon: <AppstoreOutlined />,
            //disabled: true,
        },
        {
            label: '信息反馈',
            key: '6',
           // icon: <AppstoreOutlined />,
            //disabled: true,
        },
       
        {
            label: '灾情直报',
            key: '5',
           // icon: <AppstoreOutlined />,
            //disabled: true,
        },
    */
    if (data === '1') {
      LoopMsgAPi.yhsjList({ pageNum: '6', pageSize: '10' }).then(e => {
        console.log("@e-->", e)
        setDataList(e.rows.map(e => {
          e.key = e.id
          e.approval = '待审批'
          return e
        }))
      })

    }
    else if (data === '2') {
      //排查治理list,拿出第一条展示用
      //{pageNum:'1',pageSize:'1'}
      LoopMsgAPi.yhsjList({ pageNum: '5', pageSize: '10' }).then(e => {
        console.log("@e-->", e)
        setDataList(e.rows.map(e => {
          e.key = e.id
          e.approval = '待审批'
          return e
        }))
      })
    }
    else if (data === '3') {
      LoopMsgAPi.yhsjList({ pageNum: '7', pageSize: '10' }).then(e => {
        console.log("@e-->", e)
        setDataList(e.rows.map(e => {
          let a = 0;
          e.key = e.id
          e.approval = '待审批'
          e.tq = a++
          return e
        }))
      })
      LoopMsgAPi.jyybList({ pageNum: '2', pageSize: '10' }).then(e => {
        setTqDataList(e.rows.map(e => {
          e.key = e.id
          return e
        }))
      })

    }
    else if (data === '4') {
      LoopMsgAPi.yhsjList({ pageNum: '3', pageSize: '10' }).then(e => {
        setDataList(e.rows.map(e => {
          e.key = e.id
          e.approval = '待审批'
          return e
        }))
      })



    }
    else if (data === '6') {

    }
    else if (data === '5') {
      LoopMsgAPi.yhsjList({ pageNum: '1', pageSize: '10' }).then(e => {
        setDataList(e.rows.map(e => {
          e.key = e.id
          e.approval = '待审批'
          return e
        }))
      })

    }
    // else if(data==='7'){

    // }

    /* LoopMsgAPi.rgxcList().then(e => {
        console.log("@", e.rows.map(e=>{
                e.key=e.id
                return e
        }))
        setRgxcDataArray(e.rows.map(e=>{
            e.key=e.id
            return e
    }))
        
    }) */
  }, [data])

  //从接口拿数据，根据data的值，制作成dataSource
  const dataSource = data === '2' ? dataList : data === '1' ? dataList : data === '3' ? dataList : data === '4' ? dataList : data === '5' ? dataList : null

  const columns = data === '1' ? [
    {
      title: `任务名称`,
      dataIndex: 'yhmc',
      key: 'yhmc',
      width: 600,
    },
    {
      title: `审批状态`,
      dataIndex: 'approval',
      key: 'approval',
      //width:600,
    },
    {
      title: '完成状态',
      dataIndex: 'state',
      key: 'state',
      render: (text, record) => {
        return <Button type="link" size="small" onClick={e => {
          setSwitchState(true);
          setTitle(record)
          console.log(text, record)
        }}>已完成</Button>
      }
    },

  ] : data === '2' ? [
    {
      title: `灾害风险隐患排查任务名称`,
      dataIndex: 'yhmc',
      key: 'yhmc',
      width: 600,
    },
    {
      title: `审批状态`,
      dataIndex: 'approval',
      key: 'approval',
      //width:600,
    },
    {
      title: '完成状态',
      dataIndex: 'state',
      key: 'state',
      render: (text, record) => {
        return <Button type="link" size="small" onClick={e => {
          setSwitchState(true);
          setTitle(record)
          console.log(text, record)
        }}>已完成</Button>
      }
    },

  ] : data === '3' ? [
    {
      title: `风险点名称`,
      dataIndex: 'yhmc',
      key: 'yhmc',
      width: 600,
    },

    {
      title: '完成状态',
      dataIndex: 'state',
      key: 'state',
      render: (text, record) => {
        return <Button type="link" size="small" onClick={e => {
          setSwitchState(true);
          setTitle(record)
          console.log(text, record, tqDataList)
        }}>查看</Button>
      }
    },

  ] : data === '4' ? [
    {
      title: `隐患点名称`,
      dataIndex: 'yhmc',
      key: 'yhmc',
      width: 600,
    },
    {
      title: ``,
      dataIndex: 'approval',
      key: 'approval',
      //width:600,
      render: (text, record) => {
        return <Button type="link" size="small" onClick={e => {
          setYhd(record)
          history.push(`/manager/fxyhLook/${record.id}`)
        }}>查看</Button>
      }
    },
    {
      title: '',
      dataIndex: 'state',
      key: 'state',
      render: (text, record) => {
        return <Button type="link" size="small" onClick={e => {
          setYhd(record)
          history.push(`/manager/fxyhEdit/${record.id}`)
        }}>编辑</Button>
      }
    },

  ] : data === '5' ? [
    {
      title: `灾害风险名称`,
      dataIndex: 'yhmc',
      key: 'title',
      width: 600,
    },
    
    {
      title: '审批状态',
      dataIndex: 'state',
      key: 'state',
      render: (text, record) => {
        return <Button type="link" size="small" onClick={e => {
          setSwitchState(true);
          setTitle(record)
          console.log(text, record)
        }}>待审批</Button>
      }
    },

  ] : [
    {
      title: `灾害风险名称`,
      dataIndex: 'yhmc',
      key: 'title',
      width: 600,
    },
    {
      title: `审批状态`,
      dataIndex: 'approval',
      key: 'approval',
      //width:600,
    },
    {
      title: '审批状态',
      dataIndex: 'state',
      key: 'state',
      render: (text, record) => {
        return <Button type="link" size="small" onClick={e => {
          setSwitchState(true);
          setTitle(record)
          console.log(text, record)
        }}>待审批</Button>
      }
    },

  ];




  return (
    <div>
      

      <Table scroll={{ y: 300 }} pagination={false} dataSource={dataSource} columns={columns} />



      {data === "1" && <List title={title} switchState={switchState} onOk={onOk} data={data} />}
      {data === "2" && <List title={title} switchState={switchState} onOk={onOk} data={data} />}
      {data === "3" && <List title={title} switchState={switchState} onOk={onOk} data={data} tqDataList={tqDataList} />}
      {data === "4" && <List title={title} switchState={switchState} onOk={onOk} data={data} />}
      {data === "5" && <List title={title} switchState={switchState} onOk={onOk} data={data} />}
      {data === "6" && <List title={title} switchState={switchState} onOk={onOk} data={data} />}
    </div>
  )
}
